﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Management/manage.master" AutoEventWireup="true" CodeFile="Color.aspx.cs" Inherits="Management_Common_Color" Theme="DataWebControls" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript" src="<%=ResolveUrl("~/Scripts/jquery-ui-dd-sortable.min.js") %>"></script>
    <script language="javascript" type="text/javascript">
        function formvalidate() {
            var result = true;
            $(".required").each(function () {
                if ($.trim($(this).val()) == "") {
                    $(this).next().text("* required!");
                    result = false;
                }
                else {
                    $(this).next().text("*");
                }
            });
            return result;
        }

        $(function () {
            //拖拽排序
            $("#<%=GridView1.ClientID %> tbody").sortable({
                'update': function (event, ui) {
                    console.log(ui);
                },
                //鼠标接触即开始排序
                'tolerance': 'pointer',
                //定位动画
                'revert': true,
                'opacity': 0.7,
                'cancel': '.HeaderStyle',
                'cursor': 'move'
            });

            $("#sort").click(function () {
                var colors = [];
                $("#<%=GridView1.ClientID %> tbody tr").each(function (k, v) {
                    if (k > 0) {
                        var fields = $(this).find("span");
                        colors.push({
                            ColorID: $(fields[0]).text(),
                            ColorName: $(fields[1]).text(),
                            Sort: k
                        });
                    }
                });
                $.ajax({
                    type: "POST",
                    url: '<%=ResolveUrl("~/handlers/ColorHandler.ashx") %>',
                    dataType: "json",
                    data: { colordata: JSON.stringify({ "ColorList": colors }) },
                    success: function (data) {
                        alert(data.Status == "0" ? "保存成功!" : "保存时发生错误!请重试...");
                        window.location.reload();
                    },
                    error: function (err) {
                        alert("保存时发生错误!请重试...");
                        window.location.reload();
                    }
                });
            });
        });
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" AsyncPostBackTimeout="36000">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <h2 class="clearfix">
                <span class="float_l">颜色管理</span>
            </h2>
            <asp:Panel ID="Panel1" runat="server" CssClass="block">
                <table class="table">
                    <tr>
                        <td class="field">ID:</td>
                        <td><asp:Label ID="lblID" runat="server"></asp:Label></td>
                    </tr>
                    <tr>
                        <td class="field">颜色:</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" CssClass="required text"></asp:TextBox><span class="color_red margin5_lr">*</span>
                        </td>
                    </tr>
                </table>
                <div class="margin10_tb">
                    <asp:LinkButton ID="lbtnSave" runat="server" 
                        OnClientClick="javascript:return formvalidate();" CssClass="btn" 
                        onclick="lbtnSave_Click">保存</asp:LinkButton>
                    <asp:LinkButton ID="lbtnCancel" runat="server" 
                        OnClientClick="javascript:window.location.reload();" CssClass="btn" 
                        onclick="lbtnCancel_Click">取消</asp:LinkButton>
                </div>
            </asp:Panel>
            <div class="margin10_tb">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label ID="lblID" runat="server" Text='<%#Eval("ColorID").ToString() %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="颜色">
                            <ItemTemplate>
                                <asp:Label ID="lblName" runat="server" Text='<%#Eval("ColorName").ToString() %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnEdit" CommandName="MOD" runat="server" CssClass="btn">编辑</asp:LinkButton>
                                <asp:LinkButton ID="lbtnDelete" CommandName="DEL" runat="server" CssClass="btn" OnClientClick="javascript:return confirm('确认删除么？');">删除</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <div class="pager margin10_tb">
                <asp:Repeater ID="rptPageFliper" runat="server">
                    <ItemTemplate>
                        <span class='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "current": string.Empty%>' class="paging">
                            <asp:LinkButton ID="lbtnPager" runat="server" CommandName="<%# ((PageNumberItem)Container.DataItem).PageNumberCommand%>"
                                Text="<%# ((PageNumberItem)Container.DataItem).PageNumberText%>" Enabled='<%# !(((PageNumberItem)Container.DataItem).IsCurrentPage) %>'
                                Style='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "color:#eee;": "color:#eee;"%>'
                                Font-Underline="false"></asp:LinkButton>
                        </span>
                    </ItemTemplate>
                </asp:Repeater>
                </div>
                <div class="margin10_tb">
                    <a id="sort" class="btn">保存当前排序</a>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

